<?php

abstract class AdminPresenter extends Presenter{

	public $system;
	public $session;

	protected function beforeRender(){

	}

	protected function startup(){
		
		parent::startup();
		
		$this->session = Environment::getSession()->getNamespace("system");
		$this->system = SystemModel::getInstance();
		// administrace
		$user = Environment::getUser();
		$this->template->user = $user->getIdentity();
		if($user->getIdentity()) $this->template->user_data = $user->getIdentity()->getData();
			
		$this->template->session_expires = $this->system->getOptionVariable("sess_exp")*60;
		// zaregistrujeme autentizační handler
		$user->setAuthenticationHandler(new MyAuthenticator);
		// nastavíme expiraci
		$user->setExpiration('+ 30 minutes');

		if(!$user->isAuthenticated()){
			$this->redirect('Login:default');
		}

		$this->template->prihlasen = $user->isAuthenticated();
		$this->template->add("menu", $this->system->getMenu());
		
		
		$a = Environment::getApplication()->getRequests();
		$item = $this->system->getMenuItemByName($a[0]->params[id]);

		$this->template->add("submenu", $this->system->getMenu(FALSE, $item[0]["id_menu"]));

		$this->template->presenter_name = $this->presenter->getName();
		$this->template->presenter_action = $this->presenter->getAction();
		
		$this->template->languages = $this->system->getLanguages();
		$this->template->actual_language = $this->session->admin_id_language;

		if(!empty($item[0]["name"])) $this->template->add("title", $item[0]["name"]);
		$this->setLayout("admin");

	}

	public function createSeo($name){
		$address = $name;
		 
		// nahradi znaky s diakritikou na znaky bez diakritiky
		$fromTo = array("Á" => "A", "Ä" => "A", "Č" => "C", "Ç" => "C", "Ď" => "D", "É" => "E", "Ě" => "E", "Ë" => "E", "Í" => "I", "Ň" => "N", "Ó" => "O", "Ö" => "O", "Ř" => "R", "Š" => "S", "Ť" => "T", "Ú" => "U", "Ů" => "U", "Ü" => "U", "Ý" => "Y", "Ž" => "Z", "á" => "a", "ä" => "a", "č" => "c", "ç" => "c", "ď" => "d", "é" => "e", "ě" => "e", "ë" => "e", "í" => "i", "ň" => "n", "ó" => "o", "ö" => "o", "ř" => "r", "š" => "s", "ť" => "t", "ú" => "u", "ů" => "u", "ü" => "u", "ý" => "y", "ž" => "z", " " => "-");
		$address = StrTr ($address, $fromTo);
		 
		// prevede vsechna velka pismena na mala
		$address = strtolower ($address);
		 
		// nahradi pomlckou vsechny znanky, ktera nejsou pismena
		$re = "/[^[:alpha:][:digit:]]/";
		$replacement = "-";
		$address = preg_replace ($re, $replacement, $address);
		 
		// odstrani ze zacatku a z konce retezce pomlcky
		$address = trim ($address, "-");
		 
		// odstrani z adresy pomlcky, pokud jsou dve a vice vedle sebe
		$re = "/[-]+/";
		$replacement = "-";
		$address = preg_replace ($re, $replacement, $address);

		return $address;
	}

}

?>